//
//  HMAudioPlayerAudioTimerController.m
//  HowToDo
//
//  Created by mynSoo on 2017/1/8.
//  Copyright © 2017年 KY. All rights reserved.
//

#import "HMAudioPlayerAudioTimerController.h"

#define NUMBER_OF_ROW 6
#define kHMAudioPlayerTimerCell @"HMAudioPlayerTimerCell"

@interface HMAudioPlayerTimerCell : UITableViewCell

@property (nonatomic, strong) NSString *string;
@property (nonatomic, weak) UILabel *label;
@end

@implementation HMAudioPlayerTimerCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self =  [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if(self)
    {
        [self installUI];
    }
    return self;
}

- (void)setString:(NSString *)string
{
    _string = string;
    self.label.text = string;
    
    if([string isEqualToString:@"取消"])
    {
        self.label.textColor = [UIColor colorWithHex:0xffa42f];
    }
}

- (void)installUI
{
    UILabel *label = [[UILabel alloc]init];
    self.label = label;
    [self.contentView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.offset(0);
    }];
    label.textAlignment = NSTextAlignmentCenter;
}

@end

@interface HMAudioPlayerAudioTimerController () <UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) NSArray *textArray;
@end

@implementation HMAudioPlayerAudioTimerController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self installUI];
}

- (void)installUI
{
    self.view.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 330);
    self.textArray = @[@"30分钟", @"60分钟", @"90分钟", @"播放当前音频再关闭", @"关闭倒计时", @"取消"];
    UITableView *tableview = [self installTableView];
    tableview.frame = self.view.frame;
    [self.view addSubview: tableview];
}

- (UITableView *)installTableView
{
    UITableView *tableview = [[UITableView alloc]init];
    
    tableview.delegate = self;
    
    tableview.dataSource = self;
    
    tableview.bounces = NO;
    
    tableview.rowHeight = 55;
    
    return tableview;
}

#pragma mark - datasource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return NUMBER_OF_ROW;
}

- (HMAudioPlayerTimerCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HMAudioPlayerTimerCell *cell = [[HMAudioPlayerTimerCell alloc]init];
    
    cell.string = self.textArray[indexPath.row];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(self.clickBlock)
    {
        self.clickBlock(indexPath.row);
    }
}
@end
